import { TypeOrmModule } from '@nestjs/typeorm';
import { Module } from '@nestjs/common';
import { DinnerService } from './dinner.service';
import { DinnerController } from './dinner.controller';
import { MulterModule } from '@nestjs/platform-express';
import { diskStorage } from 'multer';
import { join, extname } from 'path';
import { Dinner } from './entities/dinner.entity';

@Module({
  imports: [
    TypeOrmModule.forFeature([Dinner]),
    MulterModule.register({
      storage: diskStorage({
        destination: join(__dirname, '../static'),
        filename: (_, file, callback) => {
          const fileName = `${
            new Date().getTime() + extname(file.originalname)
          }`;
          return callback(null, fileName);
        },
      }),
    }),
  ],
  controllers: [DinnerController],
  providers: [DinnerService],
})
export class DinnerModule {}
